package pers.baiban.sqltoword.handler.impl;

import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import pers.baiban.sqltoword.handler.AbstractTableProcessor;
import pers.baiban.sqltoword.handler.TableProcessor;
import pers.baiban.sqltoword.util.TableUtil;

import java.util.List;

import static pers.baiban.sqltoword.util.TableUtil.Functors.PARAGRAPH;
import static pers.baiban.sqltoword.util.TableUtil.Functors.RUN;

/**
 * 表格内所有单元格处理器 (字体)
 *
 * @author 强子初
 * @since 2023/11/29
 */
@Component
@Order(5)
public class TableAllCellFontFamilyProcessor extends AbstractTableProcessor implements TableProcessor {

    @Override
    public void doHandler() {
        if (needUpdate(param.getTableCellFontFamily())) {
            getRun().forEach(it -> it.setFontFamily(param.getTableCellFontFamily()));
        }
    }

    /**
     * 获取表格单元格文本样式
     */
    private List<XWPFRun> getRun() {
        return TableUtil.to(cells, PARAGRAPH.andThen(RUN));
    }
}